package com.example.android_contentprovider_multimedia;

import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.main_image).setOnClickListener(this);
        findViewById(R.id.main_music).setOnClickListener(this);
        findViewById(R.id.main_video).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch ( v.getId()) {
            case R.id.main_image:
                Intent image = new Intent(Intent.ACTION_PICK);
                image.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(image, 100);
                break;
            case R.id.main_music:
                Intent music = new Intent(Intent.ACTION_PICK);
                music.setDataAndType(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "audio/*");
                startActivityForResult(music, 100);
                break;
            case R.id.main_video:
                Intent video = new Intent(Intent.ACTION_PICK);
                video.setDataAndType(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "video/*");
                startActivityForResult(video, 100);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // 接口回调，可以实现具体的操作

    }
}

